var t = require("../../@babel/runtime/helpers/interopRequireDefault"), e = t(require("../../@babel/runtime/regenerator")), a = require("../../@babel/runtime/helpers/asyncToGenerator"), i = t(require("../../http/directBuyApi")), r = t(require("../../http/info")), o = t(require("../../http/carApi")), s = t(require("../../http/system")), n = getApp(), u = new i.default(), l = (new r.default(), 
new o.default()), c = new s.default(), d = require("../../http/activityApi.js");

Page({
    data: {
        nodes: "",
        safeAreaHeight: n.global.systemInfo.safeAreaHeight,
        titleBarTotalHeight: n.global.systemInfo.titleBarTotalHeight,
        titleBarBgColor: "rgba(255,255,255,0)",
        titleBarFontColor: "rgba(0,0,0,0)",
        hideScroll: !1,
        directBuyDetails: {},
        sizeInfo: {},
        carCount: 0,
        isShow: !0,
        rules: ""
    },
    onLoad: function(t) {
        this.setData({
            productId: t.productId
        }), this.getData();
    },
    onShow: function() {
        this.selectComponent("#deliver").close(), this.postCarCount();
    },
    getData: function() {
        var t = this;
        return a(e.default.mark(function a() {
            var i, r, o;
            return e.default.wrap(function(e) {
                for (;;) switch (e.prev = e.next) {
                  case 0:
                    return e.prev = 0, wx.showLoading({
                        title: "加载中",
                        mask: !0
                    }), i = u.directBuyDetails(t.data.productId), r = u.directBuySize(t.data.productId), 
                    e.next = 6, Promise.allSettled([ i, r ]);

                  case 6:
                    "fulfilled" == (o = e.sent)[0].status && t.getDirectBuyDetails(o[0].value), "fulfilled" == o[1].status && t.getDirectBuySize(o[1].value), 
                    e.next = 13;
                    break;

                  case 11:
                    e.prev = 11, e.t0 = e.catch(0);

                  case 13:
                    return e.prev = 13, wx.hideLoading(), e.finish(13);

                  case 16:
                  case "end":
                    return e.stop();
                }
            }, a, null, [ [ 0, 11, 13, 16 ] ]);
        }))();
    },
    loadTopRank: function(t) {
        var i = this;
        return a(e.default.mark(function a() {
            return e.default.wrap(function(e) {
                for (;;) switch (e.prev = e.next) {
                  case 0:
                    d.rankProductIndex({
                        productNo: t
                    }).then(function(t) {
                        i.setData({
                            rankInfo: t.data
                        });
                    }).catch(function(t) {});

                  case 1:
                  case "end":
                    return e.stop();
                }
            }, a);
        }))();
    },
    getDirectBuyDetails: function(t) {
        t.data.videoList = t.data.productVideo ? [ t.data.productVideo ] : [], this.setData({
            directBuyDetails: t.data
        }), this.loadTopRank(t.data.productNo);
    },
    getDirectBuySize: function(t) {
        t.data.videoList = t.data.productVideo ? [ t.data.productVideo ] : [];
        var e = t.data, a = e.ipEnglishName || ("潮玩公社" == e.ipName ? "" : e.ipName);
        e.goodsTitle = a + e.productTitle, e.productSpecListVo = e.productSpecListVo ? e.productSpecListVo : [], 
        e.limitNum = this.data.directBuyDetails.limitNum, e.stock = this.data.directBuyDetails.stock, 
        e.productId = this.data.directBuyDetails.productId, e.estimatedDeliveryTime = this.data.directBuyDetails.estimatedDeliveryTime && this.data.directBuyDetails.estimatedDeliveryTime.substring(0, 10), 
        e.showSupportTips = this.data.directBuyDetails.showSupportTips, this.setData({
            sizeInfo: e
        });
    },
    getCarCount: function(t) {
        this.setData({
            carCount: t.data.cartNum
        });
    },
    postCarCount: function() {
        var t = this;
        l.carCount().then(function(e) {
            t.getCarCount(e);
        });
    },
    showBuy: function(t) {
        !this.data.sizeInfo.productSpecListVo || this.data.sizeInfo.productSpecListVo, this.setData({
            isShow: t.detail.isShow
        }), this.changeScroll(), this.selectComponent("#buy").showPopup();
    },
    showCar: function(t) {
        this.setData({
            isShow: t.detail.isShow
        }), this.changeScroll(), this.selectComponent("#buy").showPopup();
    },
    showDeliver: function() {
        this.selectComponent("#deliver").showPopup();
    },
    showRules: function() {
        this.selectComponent("#rules").showPopup(), this.changeScroll(), !this.data.rules && this.getRules();
    },
    getRules: function() {
        var t = this;
        return a(e.default.mark(function a() {
            var i;
            return e.default.wrap(function(e) {
                for (;;) switch (e.prev = e.next) {
                  case 0:
                    return e.next = 2, c.getSystemConfig("DeliveryRule");

                  case 2:
                    i = e.sent, t.setData({
                        rules: i.data.configValue
                    });

                  case 4:
                  case "end":
                    return e.stop();
                }
            }, a);
        }))();
    },
    onShareAppMessage: function(t) {
        return {
            title: this.data.directBuyDetails.shareTitle,
            imageUrl: this.data.directBuyDetails.sharePic
        };
    },
    changeScroll: function() {
        this.setData({
            hideScroll: !this.data.hideScroll
        });
    },
    onPageScroll: function(t) {
        var e = t.scrollTop;
        if (e > this.data.titleBarTotalHeight) this.setData({
            titleBarBgColor: "rgba(255,255,255,1);",
            titleBarFontColor: "rgba(0,0,0,1);"
        }); else if (e > 0 < this.data.titleBarTotalHeight) {
            var a = 1 / this.data.titleBarTotalHeight * e;
            this.setData({
                titleBarBgColor: "rgba(255,255,255,".concat(a, ');"'),
                titleBarFontColor: "rgba(0,0,0,".concat(a, ")")
            });
        } else this.setData({
            titleBarBgColor: "rgba(255,255,255,0);",
            titleBarFontColor: "rgba(0,0,0,0);"
        });
    }
});